<template>
  <div>
    <FilterTable
      ref="maintenanceTable"
      :columns="maintenanceColumns"
      :dataSource="maintenanceList"
      :isToperInfo="false"
      :isColumnFilter="false"
      :isMemoryPagination="true"
      :height="400"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.maintenanceColumns = columns)"
    ></FilterTable>
  </div>
</template>

<script>
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import { getLabourPayObject } from '@/api/finance/repairFinance/cancelFinance';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import { getRepairTypes } from '@/api/repair/repairReception/feesSettlement';
export default {
  name: 'Maintenanceproject',
  mixins: [dictionary],
  props: ['vehicleDetailsVin', 'list', 'resetTable'],
  data() {
    this.BaseTable = null;
    this.dmsFunc = { dmsFuncId: 55100010 };
    return {
      maintenanceColumns: this.createMaintenanceColumns(),
      maintenanceList: [],
      technicianDate: [], // 责任技师列表
      repairList: [] // 维修列表类型
    };
  },
  watch: {
    list(val) {
      this.insertRecords(val);
    },
    resetTable(val) {
      if (val) {
        // this.BaseTable.RESET_TABLE_DATA();
        this.maintenanceList = [];
      }
    }
  },
  mounted() {
    this.BaseTable = this.$refs.maintenanceTable.$refs.pageTable;
    if (!this.resetTable) {
      this.maintenanceList = [];
    }
    this.serviceConsultant();
    this.getRepairTypesFun(); // 获取维修类型
  },
  created() {
    // this.dmsFunc = {dmsFuncId:35100010};
    // this.protectRepairFun(this.vehicleDetailsVin);
  },
  methods: {
    createMaintenanceColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '收费类别',
        //   dataIndex: 'MANAGE_SORT_NAME',
        //   width: 150,
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        //   // align:"center"
        // },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          width: 150,
          sorter: true,
          filter: true,
          render: props => {
            return <div>{this.getRepairTypeName(props.row.REPAIR_TYPE_CODE)}</div>;
          }
          // filterType: 'input',
          //  render: props => {
          //   return <div>{this.createDictText(props.row.REPAIR_TYPE_CODE, '8000')}</div>;
          // }
          // align:"center"
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          width: 150,
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODEF',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 150,
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.getEmployeeName(props.row.TECHNICIAN)}</div>;
          }
          // align:"center"
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '折扣金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '收费工时',
          dataIndex: 'STD_LABOUR_HOUR',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
          // align:"center"
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          width: 170,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '检查结果',
          dataIndex: 'TROUBLE_DESC',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '组合代码',
          dataIndex: 'PACKAGE_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '套餐代码',
          dataIndex: 'SERVICE_PACKAGE_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          width: 150,
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input'
          // align:"center"
        }
      ];
    },
    orderListChangeHandle(val) {},
    insertRecords(list) {
      this.maintenanceList = list;
      // this.BaseTable.EXECUTE_INSERT(list);
    },
    // 根据userId查employeeName
    getEmployeeName(userId) {
      const item = this.technicianDate.find(x => {
        return x.value == userId;
      });
      return item ? item.text : '';
    },
    // 责任技师接口数据
    async serviceConsultant() {
      let technician = { role: dictCode.TECHNICIAN }; // 指定技师
      const technicianRes = await searchRoleByCodes(technician);
      this.technicianDate = technicianRes.data.map(x => ({ text: x.employeeName, value: x.userId }));
      console.log(JSON.stringify(this.technicianDate), '责任技师');
    },
    // 根据code查维修类型名称
    getRepairTypeName(code) {
      console.log(code, '----code');
      const item = this.repairList.find(x => {
        return x.value == code;
      });
      return item ? item.text : '';
    },
    // 获取维修类型
    async getRepairTypesFun() {
      const res = await getRepairTypes(this.dmsFunc);
      this.repairList = res.data.map(x => ({ value: x.REPAIR_TYPE_CODE, text: x.REPAIR_TYPE_NAME }));
      console.log(JSON.stringify(this.repairList), '维修项目维修类型-----');
    }
  }
};
</script>

<style lang="less">
.custom-wrap {
  height: calc(100vh - 145px);
  // position: relative;
}
</style>
